/**
 * Created by Julia on 2016/5/4.
 */
define(['jquery'], function ($) {
    return {
        second_to_date: function (second) {
            var h, m, s;
            var time = parseInt(second);
            if (null != time && "" != time) {
                if (time > 60 && time < 60 * 60) {
                    m = parseInt(time / 60.0);
                    s = parseInt((parseFloat(time / 60.0) - parseInt(time / 60.0)) * 60);
                    m = m >= 10 ? m : ('0' + m);
                    s = s >= 10 ? s : ('0' + s);
                    time = "00:" + m + ":" + s;
                }
                else if (time >= 60 * 60 && time < 60 * 60 * 24) {
                    h = parseInt(time / 3600.0);
                    m = parseInt((parseFloat(time / 3600.0) - parseInt(time / 3600.0)) * 60);
                    s = parseInt((parseFloat((parseFloat(time / 3600.0) - parseInt(time / 3600.0)) * 60) -
                            parseInt((parseFloat(time / 3600.0) - parseInt(time / 3600.0)) * 60)) * 60);
                    h = h >= 10 ? h : ('0' + h);
                    m = m >= 10 ? m : ('0' + m);
                    s = s >= 10 ? s : ('0' + s);

                    time = h + ":" + m + ":" + s;
                }
                else {
                    time = parseInt(time) >= 10 ? "00:00:" + parseInt(time) : ('00:00:0' + parseInt(time));
                }
            } else {
                time = '00:00:00';

            }

            return time;
        },
        unix_to_datetime: function(unix) {
            if (unix == null) {
                return '-';
            }
            else {
                var date = new Date(unix);
                Y = date.getFullYear() + '-';
                M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '-';
                D = (date.getDate() + 1 > 10) ? (date.getDate() + ' ') : ('0' + date.getDate()) + ' ';
                h = (date.getHours() >= 10) ? (date.getHours() + ':') : ('0' + date.getHours() + ':');
                m = (date.getMinutes() >= 10) ? (date.getMinutes() + ':') : ('0' + date.getMinutes() + ':');
                s = (date.getSeconds() >= 10) ? (date.getSeconds() + ' ') : ('0' + date.getSeconds());

                return (Y + M + D + h + m + s);
            }
        },
        getYesterdayDateTime: function () {
            var date = new Date ();
            var currentDate = new Date(date.setTime(date.getTime()-24*60*60*1000)).Format("yyyy-MM-dd HH:mm:ss");
            return currentDate;
        },
        getCurrentDateTime: function () {
            var date = new Date ();
            var endData = new Date(date).Format("yyyy-MM-dd HH:mm:ss");
            return endData;
        }
    }
});